package org.base.sys.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.base.sys.VO.SysMenuPermissionVO;
import org.base.sys.VO.TreeMenuVO;
import org.base.sys.service.SysRoleService;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.base.common.controller.BaseController;
import org.base.sys.pojo.SysMenuPermission;
import org.base.sys.service.SysMenuPermissionService;
import org.base.sys.query.SysMenuPermissionQuery;
import java.util.List;
import javax.validation.Valid;

import org.base.common.pojo.PageResult;

/**
 * <p>
 * 菜单权限表 前端控制器
 * </p>
 *
 * @author AutoGenerator
 * @since 2020-05-27
 */
@Api(value = "菜单权限表", tags = "菜单权限表")
@Validated
@AllArgsConstructor
@RestController
@RequestMapping("/sys-menu-permission")
@Slf4j
public class SysMenuPermissionController extends BaseController<SysMenuPermission, SysMenuPermissionService> {

    private SysRoleService roleService;
    /**
    * 添加
    */
    @PostMapping("/add")
    @ApiOperation(value = "添加菜单权限表")
    public boolean add(@Valid @RequestBody SysMenuPermission entity){
        return service.save(entity);
    }

    /**
    * 根据id查询
    */
    @GetMapping("/{id}")
    @ApiOperation(value = "根据id查询菜单权限表")
    public SysMenuPermission get(@PathVariable("id") Long id){
        return service.getById(id);
    }

    /**
    * 更新
    */
    @PutMapping("/update")
    @ApiOperation(value = "根据id更新菜单权限表")
    public boolean update(@Valid @RequestBody SysMenuPermission entity){
        return service.updateById(entity);
    }

    /**
    * 查询
    */
    @GetMapping("/query")
    @ApiOperation(value = "列表查询菜单权限表")
    public List<SysMenuPermission> query(SysMenuPermissionQuery query){
        return service.getByQuery(query);
    }

    /**
    * 分页查询
    */
    @GetMapping("/pageQuery")
    @ApiOperation(value = "分页查询菜单权限表")
    public PageResult pageQuery(SysMenuPermissionQuery query){
        return service.getByPageQuery(query);
    }

    @GetMapping("/treeMenus")
    @ApiOperation(value = "查询树形菜单")
    public List<TreeMenuVO> treeMenus() {
        return service.getTreeMenu();
    }

    @PutMapping("/hideMenu/{id}")
    @ApiOperation(value = "隐藏菜单")
    public boolean hideMenu(@PathVariable("id") Long id) {
        return service.hide(id);
    }

    @PutMapping("/showMenu/{id}")
    @ApiOperation(value = "显示菜单")
    public boolean showMenu(@PathVariable("id") Long id) {
        return service.show(id);
    }

    /**
     * 添加或者保存
     */
    @PostMapping("/saveOrUpdate")
    public boolean saveOrUpdate(@Valid @RequestBody SysMenuPermission entity){
        return service.saveOrUpdate(entity);
    }

    @GetMapping("/parenMenus/{parentId}")
    @ApiOperation(value = "查询树形菜单")
    public List<SysMenuPermission> parenMenus(@PathVariable("parentId") Long parentId) {
        return service.getParenMenus(parentId);
    }

    @GetMapping("/menus")
    @ApiOperation(value = "菜单")
    public List<SysMenuPermission> getMenus() {
        return service.getMenus();
    }

    @GetMapping("/treeMenuPermission")
    @ApiOperation(value = "查询用户菜单权限")
    public List<SysMenuPermissionVO> getTreeMenuPermission() {
        return service.getTreeMenuPermission();
    }

    @GetMapping("/perms")
    @ApiOperation(value = "查询权限")
    public List<SysMenuPermission> getPerms() {
        return service.getPerms();
    }
}

